// 页面路径：store/index.js
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);//vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
    state: {//存放状态
        tabbarCurrent: 0,
        userWannaPerformanceIds: [],
        searchCity: '上海',
        // 跳转后一次性消耗的type
        takeType: undefined,
        loginUserInfo: {},
    },
    mutations: {
        changeTakeType(state, type) {
            state.takeType = type;
        },
        changeSearchCity(state, city) {
            state.searchCity = city;
        },
        ChangeTabbarCount(state, current) {
            state.tabbarCurrent = current

        },
        initUserWanna(state, wannaList) {
            state.userWannaPerformanceIds = wannaList;
        },
        userDoWanna(state, id) {
            state.userWannaPerformanceIds.push(id);
        },
        userRemoveWanna(state, id) {
            const index = state.userWannaPerformanceIds.indexOf(id);
            if (index !== -1) {
                state.userWannaPerformanceIds.splice(index, 1);
            }
        },
        saveUserInfo(state, loginUserInfo) {
            state.loginUserInfo = loginUserInfo;
        }
    }
})
export default store
